package com.iwhalecloud.bss.kite.cucc.common.util;

import java.util.Collection;
import javax.annotation.Nullable;

import org.springframework.util.CollectionUtils;

import com.iwhalecloud.bss.kite.common.constant.IErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;

/**
 * @ClassName : KiteAssert
 * @Description : 断言工具类 抛出BssException
 * @Author : xie.zhengjun
 * @Date : 2020/10/2 15:46
 */
public class KiteAssert {
    public static void state(boolean expression, IErrorConsts errorCode, Object... args) {
        if (!expression) {
            errorCode.throwOut(args);
        }
    }

    public static void notNull(@Nullable Object object, IErrorConsts errorCode, Object... args) {
        if (object == null) {
            errorCode.throwOut(args);
        }
    }

    public static void notEmpty(@Nullable Collection<?> collection, IErrorConsts errorCode, Object... args) {
        if (CollectionUtils.isEmpty(collection)) {
            errorCode.throwOut(args);
        }
    }

    public static void empty(@Nullable Collection<?> collection, IErrorConsts errorCode, Object... args) {
        if (!CollectionUtils.isEmpty(collection)) {
            errorCode.throwOut(args);
        }
    }

    public static void notBlank(@Nullable String str, IErrorConsts errorCode, Object... args) {
        if (KiteStringUtils.isBlank(str)) {
            errorCode.throwOut(args);
        }
    }
}
